package nbcp.myoql.db.es.extend

import nbcp.base.comm.JsonMap
import nbcp.base.extend.*
import org.elasticsearch.client.*

/**
 * Created by udi on 17-7-10.
 */


/**
 * 获取所有别名索引。
 */
fun RestClient.getAllIndex(): Set<String> {
    var result = this.performRequest(Request("GET", "/_cat/aliases?format=json"));
    if (result.statusLine.statusCode != 200) {
        return setOf()
    }

    var list = result.entity.content.readContentString().FromListJson(JsonMap::class.java);

    return list
        .filter { it.get("is_write_index").AsBoolean() }
        .map { it.get("alias").AsString() }
        .toSet()
}
